<?php

class guestbookAdminPlugin extends commonMod
{
    public function __construct()
    {
        parent::__construct();
        $config['TPL_TEMPLATE_PATH'] = dirname(__file__) . '/template/';
        $this->tpl = new cpTemplate($config);
    }


    //本插件后台首页
    public function index()
    {
        //以下为插件类方法
		$url=__URL__.'/index-page-{page}.html';//分页基准网址 
		$page=new Page();
		$listRows=20;//每页显示的信息条数
		$cur_page=$page->getCurPage($url);
		$limit_start=($cur_page-1)*$listRows;         
		$limit=$limit_start.','.$listRows; 

		$count=$this->model->table('extend_guestbook')->count();	 //获取行数	
		$list=$this->model->table('extend_guestbook')->order('id desc')->limit($limit)->select();
		$this->assign('list',$list);
		$this->assign('alist',$alist);
		$this->assign('page',$this->page($url,$count,$listRows));
		$this->display('admin_index');


    }

    //删除信息
    public function del()
    {
		if (empty($_GET[0]))
        {
            $this->error('参数传递错误！');
            return;
        }
        $condition['id'] = intval($_GET[0]);
        $this->model->table('extend_guestbook')->where($condition)->delete();
        $this->success('删除成功！');
        return;

    }

    //详细信息
    public function info()
    {
		if (empty($_POST['psot_do']))
        {
            $condition['id'] = intval($_GET[0]);
            $info = $this->model->table('extend_guestbook')->where($condition)->find();
            $this->assign('info', $info);
            $this->display('admin_info');
            return;
        }

        if (empty($_POST['id']))
        {
            $this->error('参数传递错误！');
            return;
        }
        $data['reply'] = html_in($_POST['reply']);
        $data['status'] = in($_POST['status']);
        $condition['id'] = intval($_POST['id']);
        $this->model->table('extend_guestbook')->data($data)->where($condition)->update();

        $this->success('修改成功！');


    }


    // 批量操作
    public function batch_manage()
    {
		
		$mode = intval($_POST['mode']);
        $checkbox = $_POST['id'];
        if (empty($checkbox))
        {
            $this->error('未选择预约！');
            exit;
        }
        $in=implode(',',$checkbox);
        $condition = "id in($in)";
        switch ($mode)
        {
            case 1:
                $this->model->table('extend_guestbook')->where($condition)->delete();
                break;
            case 2:
                $this->model->table('extend_guestbook')->data('status=0')->where($condition)->
                    update();
                break;
            case 3:
                $this->model->table('extend_guestbook')->data('status=1')->where($condition)->
                    update();
                break;
        }
        $this->success('批量操作成功！');
        return;
    }


    //留言设置
    public function adminsetting()
    {
            $this->assign('info', $this->plus_configout());
            $this->display('admin_setting');
        
    }

    //留言设置
    public function settingseve()
    {

        $data['AUDIT']=$_POST['AUDIT'];
        $data['ipdis']=$_POST['ipdis'];
        $data['filter']=$_POST['filter'];
        $data['page']=$_POST['page'];
        $this->plus_configin($data);//修改配置
        $this->success('留言设置成功！');
        
    }
}

?>